<template>
  <div>
    <Row class="header" type="flex" justify="start">
      <Col span="24">
        <Icon class="icon" type="ios-podium-outline"/>
        <span class="title">区县上报人员/在家留观/集中留观总量统计</span>
      </Col>
    </Row>
    <br>
    <div id="area" :style="{ width: width + 'px', height: height + 'px'}"></div>
  </div>
</template>

<script>
import echarts from 'echarts'
import { sumAllList } from '@/api/yi-qing-fang-kong'
// import mockData from './mockData'

export default {
  name: 'AreaEchart',
  data () {
    return {
      chartData: []
    }
  },
  props: {
    width: {
      type: Number,
      default: () => {
        return 500
      }
    },
    height: {
      type: Number,
      default: () => {
        return 300
      }
    }
  },
  mounted () {
    this.chart()
  },
  methods: {
    chart () {
      sumAllList().then(ret => {
        if (ret.data.errcode === 0) {
          this.chartData = ret.data.data
          let option = {
            title: {
              text: ''
            },
            textStyle: {
              color: '#bababa'
            },
            legend: {
              left: '20%',
              itemHeight: 10,
              padding: [0, 0, 10, 0]
            },
            tooltip: {
              trigger: 'axis',
              backgroundColor: 'rgba(50,50,50,0.6)',
              axisPointer: { // 坐标轴指示器，坐标轴触发有效
                type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
              }
            },
            dataset: {
              dimensions: ['area', 'report', 'home', 'focus'],
              source: []
            },
            yAxis: {
              name: '单位：人',
              type: 'value',
              axisLine: {
                lineStyle: {
                  color: '#bababa' // 轴及其文字颜色
                }
              }
            },
            xAxis: {
              type: 'category',
              axisLine: {
                lineStyle: {
                  color: '#bababa' // 轴及其文字颜色
                }
              },
              axisLabel: {
                interval: 0,
                rotate: 40
              }
            },
            series: [
              {
                name: '上报人员数量',
                type: 'bar',
                label: {
                  // normal: {
                  //   show: true,
                  //   position: 'inside',
                  //   color: ['#fff']
                  // }
                },
                itemStyle: {
                // 通常情况下：
                  normal: {
                    color: ['#57B1EE']
                  },
                  // 鼠标悬停时：
                  emphasis: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                  }
                }
              },
              {
                name: '在家留观数量',
                type: 'bar',
                label: {
                  // normal: {
                  //   show: true,
                  //   position: 'inside',
                  //   color: ['#fff']
                  // }
                },
                itemStyle: {
                // 通常情况下：
                  normal: {
                    color: ['#6DD9DB']
                  },
                  // 鼠标悬停时：
                  emphasis: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                  }
                }
              },
              {
                name: '集中留观数量',
                type: 'bar',
                label: {
                  // normal: {
                  //   show: true,
                  //   position: 'inside',
                  //   color: ['#fff']
                  // }
                },
                itemStyle: {
                // 通常情况下：
                  normal: {
                    color: ['#B8A3DF']
                  },
                  // 鼠标悬停时：
                  emphasis: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                  }
                }
              }
            ]
          }
          this.chartData.forEach(item => {
            option.dataset.source.push(item)
          })
          let myChart = echarts.init(document.getElementById('area'))
          myChart.setOption(option)
        } else {
          this.$Message.error({
            content: '数据获取失败,\n' + ret.data.errmsg
          })
        }
      })
    }
  }
}
</script>

<style scoped>
  .header {
    height: 30px;
  }

  .icon {
    font-size: 28px;
    font-weight: 600;
    margin-right: 5px;
  }

  .title {
    font-size: 16px;
    font-weight: 600;
    line-height: 30px;
  }
</style>
